package com.sinosoft.sonar.examples.wrong;

import com.sinosoft.sonar.domain.MyCustomer;

import java.math.BigDecimal;

public class Demo01 {
    public int floatEquals(){
        float a1 = 10.222222225f;

        float b1 = 10.222222329f;
        System.out.println("a1:"+Float.toString(a1));
        System.out.println("b1:"+Float.toString(b1));
        if(a1 == b1){
            System.out.println("a1等于b1");
        }else{
            System.out.println("a1不等于b1");
        }
        return 1;
    }

    public void compareByOperator() {
        float f1 = 0.0f;
        for (int i = 0; i < 11; i++) {
            f1 += 0.1f;
        }

        float f2 = 0.1f * 11;

        System.out.println("f1 = " + f1);
        System.out.println("f2 = " + f2);

        if (f1 == f2) {
            System.out.println("f1和f2是相等的");
        } else {
            System.out.println("f1和f2是不相等的");
        }
    }

    public void question_11(String str1,String str2,String str3){
        String[] list = new String[]{str1,str2,str3};
        System.out.println("当前数组内容为："+list.toString());
        for(int i=0;i<list.length;i++){
            if(list[i] == null){
                System.out.println(i+1);
            }
        }
    }

    public void question_18(){
        BigDecimal a = BigDecimal.ZERO;
        BigDecimal b = new BigDecimal(0);
        BigDecimal c = new BigDecimal("1.1");
        BigDecimal d = new BigDecimal(1.1f);
    }

    public void question_16(){
        MyCustomerServiceImpl myCustomerServiceImpl = new MyCustomerServiceImpl();
        Integer customId = 15;

        MyCustomer myCustomer = myCustomerServiceImpl.getCustomerById(customId);
        String sex = myCustomer.getSex();
        if(myCustomer!=null){
            if("男".equals(sex)){
                System.out.println("......");
            }
        }
    }

    public void question_20(){
        try{
            testException();
            System.out.println("执行成功！");
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }


    public void testException() throws Exception{
        try{
            throw new Exception("try异常！");
        }catch(Exception e){
            throw e;
        }finally{
            throw new Exception("finally异常!");
        }
    }
}
